package com.fs.generator;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import lombok.Data;

@Data
public class GenerateConfiguration {

	/*******************************/
	/******** service 设置 *********/
	/*******************************/
	/** 工作目录 */
	private String workspace;
	/** 目标根package */
	private String rootPackage;

	private String codePath = "java";

	private String resourcePath = "resources";

	private String testPath = "test";

	/*******************************/
	/*********** 模板设置 ***********/
	/*******************************/
	private String templatePath;

	/*******************************/
	/********** 生成选项 ************/
	/*******************************/
	private String generateOptions;

	/*******************************/
	/******** web 工程设置 **********/
	/*******************************/

	// web工程目录
	private String webWorkspace;

	// controller 包名
	private String webPackage;

	private String webappPath = "webapp";

	/** jsp 文件路径 */
	private String pagePath = "/admin/";

	/** url 访问路径 */
	private String pageMapping;

	/** 权限 前缀 */
	private String permissionsName;

	/** jsp 前缀 */
	private String pagePrefix;

	/** 查询条件字段 */
	private String searchColumns;

	/** 列表显示字段 */
	private String listColumns;

	/** 增加修改字段 */
	private String detailColumns;

	/** 详细显示字段 */
	private String viewColumns;

	public List<String> getSearchColumnsList() {
		return toList(searchColumns);
	}

	public List<String> getListColumnsList() {
		return toList(listColumns);
	}

	public List<String> getDetailColumnsList() {
		return toList(detailColumns);
	}

	public List<String> getViewColumnsList() {
		return toList(viewColumns);
	}

	private List<String> toList(String str) {
		List<String> strList = new ArrayList<String>();
		if (StringUtils.isNotBlank(str)) {
			String[] strs = str.split(",");
			for (String s : strs) {
				if (StringUtils.isNotBlank(s)) {
					strList.add(s.trim().toLowerCase());
				}
			}
		}
		return strList;
	}

	public boolean isGenerate(String beanName) {
		if (StringUtils.isBlank(generateOptions)) {
			return true;
		}
		String moduleName = "";
		if ("domainModuleGenerator".equalsIgnoreCase(beanName)) {
			moduleName = "domain";
		} else if ("jpaDaoModuleGenerator".equalsIgnoreCase(beanName)) {
			moduleName = "dao";
		} else if ("serviceInterfaceModuleGenerator".equalsIgnoreCase(beanName)) {
			moduleName = "service";
		} else if ("serviceImplModuleGenerator".equalsIgnoreCase(beanName)) {
			moduleName = "service";
		} else if ("managerControllerModuleGenerator".equalsIgnoreCase(beanName)) {
			moduleName = "controller";
		} else if ("pagesModuleGenerator".equalsIgnoreCase(beanName)) {
			moduleName = "page";
		}
		return toList(generateOptions).contains(moduleName);
	}

}
